package com.caimiao.miao.http;

import com.caimiao.miao.bean.Device;
import com.caimiao.miao.bean.Response;
import com.caimiao.miao.bean.TicketIn;
import com.caimiao.miao.bean.TicketOut;
import com.caimiao.miao.http.retorfit.RetrofitFactory;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;

public class HttpUtil {

    /**
     * 设备注册
     *
     * @param deviceId
     * @return
     */
    public static Observable<Response> postInitDevice(String deviceId) {
        return RetrofitFactory.api().postInitDevice(deviceId);
    }

    /**
     * 设备状态更新
     *
     * @param device
     * @return
     */
    public static Observable<Response> postUpdateDevice(Device device) {
        Map<String, Object> params = new HashMap<>();
        params.put("dev_code", device.getDeviceId());
        params.put("longtitude", device.getLongitude());
        params.put("latitude", device.getLatitude());
        params.put("net_type", device.getNetStatus());
        params.put("online_state", "1");
        params.put("powder_state", device.getBatteryStatus());
        return RetrofitFactory.api().postUpdateDevice(params);
    }

    /**
     * 上传入库数据
     *
     * @param ticket
     * @return
     */
    public static Observable<Response> postInTicket(TicketIn ticket) {
        Map<String, Object> params = new HashMap<>();
        params.put("dev_code", ticket.getDevice());
        params.put("ticket_num", ticket.getCount());
        params.put("ticket_type", ticket.getType());
        return RetrofitFactory.api().postAddTicket(params);
    }

    /**
     * 上传出票结果
     *
     * @param ticket
     * @return
     */
    public static Observable<Response> postOutTicket(TicketOut ticket) {
        Map<String, Object> params = new HashMap<>();
        params.put("trade_num", ticket.getOut_trade_no());
        params.put("trade_state", ticket.getState());
        return RetrofitFactory.api().postOutTicket(params);
    }

    /**
     * 获取待出票信息
     *
     * @param deviceId
     * @return
     */
    public static Observable<Response<TicketOut>> getTicketOut(String deviceId) {
        return RetrofitFactory.api().getTicketOut(deviceId);
    }

}
